package com.qst.controller;

import com.qst.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Eumenides.
 * @create 2021-06-10 16:18
 */
@Controller
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @RequestMapping("/check")
    public void check(String name, HttpServletResponse response) throws IOException {
        response.setCharacterEncoding("utf8");
        if (name.length() > 10) {
            response.getWriter().append("用户名过长");
            return;
        } else {
            response.getWriter().append(null);
        }
    }

    @RequestMapping("/toSelect")
    public String toSelect() {
        return "select";
    }

    @RequestMapping("/select")
    public String select(String username, Model model) {
        if (username.equals("")) {
            model.addAttribute("msg", "请输入姓名");
            return "select";
        }
        model.addAttribute("msg", "");
        model.addAttribute("users", customerService.findCustomerByName(username));
        return "result";
    }
}
